home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / C / creatask.c < prev    next >
C/C++ Source or Header  |  1985-10-30  |  2KB  |  59 lines

  1.  
  2. #include "exec/types.h"
  3. #include "exec/nodes.h"
  4. #include "exec/lists.h"
  5. #include "exec/memory.h"
  6. #include "exec/interrupts.h"
  7. #include "exec/ports.h"
  8. #include "exec/libraries.h"
  9. #include "exec/tasks.h"
  10. #include "exec/execbase.h"
  11.  
  12. extern APTR AllocMem();
  13. extern struct Task *FindTask();
  14.  
  15. /*
  16.  *  Create a task with given name, priority, and stack size.
  17.  *  It will use the default exception and trap handlers for now.
  18.  */
  19. struct Task *CreateTask(name, pri, initPC, stackSize)
  20.     char *name;
  21.     UBYTE pri;
  22.     APTR  initPC;
  23.     ULONG stackSize;
  24. {
  25.     struct Task *newTask;
  26.     ULONG dataSize = (stackSize & 0xfffffc) + 1;
  27.  
  28.     /*
  29.      * This should be broken into two allocations: task of PUBLIC
  30.      * and stack of PRIVATE
  31.      */
  32.     newTask = AllocMem ((ULONG) sizeof (*newTask) + dataSize,
  33.                                 MEMF_CLEAR |MEMF_PUBLIC);
  34.  
  35.     if (!(ULONG) newTask) {
  36.         return ((struct Task *) (0));
  37.     }
  38.  
  39.     newTask -> tc_SPLower = (APTR)((long) newTask + (long) sizeof (*newTask));
  40.     newTask -> tc_SPUpper = (APTR)(((ULONG)(newTask -> tc_SPLower) + dataSize)
  41.                                 & 0xfffffe);
  42.     newTask -> tc_SPReg = (APTR) ((long) (newTask -> tc_SPUpper));
  43.  
  44.     newTask -> tc_Node.ln_Type = NT_TASK;
  45.     newTask -> tc_Node.ln_Pri = pri;
  46.     newTask -> tc_Node.ln_Name = name;
  47.  
  48.     AddTask (newTask, initPC, 0);
  49.     return (newTask);
  50. }
  51.  
  52.  
  53. DeleteTask(tc)
  54.     struct Task *tc;
  55. {
  56.     RemTask (tc);  /* does not handle self deletion properly */
  57.     FreeMem (tc, (ULONG) (tc -> tc_SPUpper) - (ULONG) tc);
  58. }
  59.